package com.fone.player.entity;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 
 * 媒体文件夹
 * 
 * @author wangyang
 * @since 2014年4月30日
 */
public class MediaFolder implements Parcelable {

	public static final String MEDIA_FOLDER_LIST = "media_folder_list";
	// 文件夹名称
	private String mMediaFolderName;
	// 父路径
	private String mMediaFolderParentPath;
	// 文件夹绝对路径
	private String mMediaFolderPath;
	// 文件夹中文件总大小
	private long mMediaFolderTotalSize;
	// 文件夹中文件总数
	private int mMediaFolderTotalNum;
	// 媒体文件集合
	private ArrayList<MediaFile> mMediaFileList = new ArrayList<MediaFile>();

	/**
	 * 
	 * 获取文件夹中文件集合总大小
	 * 
	 * @return long 文件总大小,单位是字节
	 */
	public long getMediaFolderTotalSize() {
		return mMediaFolderTotalSize;
	}

	/**
	 * 
	 * 获取文件夹中文件集合总个数
	 * 
	 * @return int 文件总个数
	 */
	public int getMediaFolderTotalNum() {
		return mMediaFolderTotalNum;
	}

	/**
	 * 
	 * 获取文件夹中文件集合
	 * 
	 * @return ArrayList<MediaFile> 文件集合
	 */
	public ArrayList<MediaFile> getMediaFileList() {
		return mMediaFileList;
	}

	/**
	 * 添加文件到集合中
	 * 
	 * @param mediaFile
	 *            文件对象
	 * @return void
	 */
	public void addMediaFile(MediaFile mediaFile) {

		if (mediaFile == null) {
			return;
		}
		mMediaFileList.add(mediaFile);
		mMediaFolderTotalNum++;
		mMediaFolderTotalSize += mediaFile.getMediaFileSize();
	}

	/**
	 * 
	 * 设置文件夹中文件数量
	 * 
	 * @param mediaFolderTotalNum
	 *            文件夹中文件数量
	 * @return void
	 */
	public void setMediaFolderTotalNum(int mediaFolderTotalNum) {
		mMediaFolderTotalNum = mediaFolderTotalNum;
	}

	/**
	 * 
	 * 获取文件夹名称
	 * 
	 * @return String 文件夹名称
	 */
	public String getMediaFolderName() {
		return mMediaFolderName != null ? mMediaFolderName : "";
	}

	/**
	 * 
	 * 设置文件夹名称
	 * 
	 * @param mediaFolderName
	 *            文件夹名称
	 * @return void
	 */
	public void setMediaFolderName(String mediaFolderName) {

		mMediaFolderName = mediaFolderName;
	}

	/**
	 * 
	 * 获取文件夹父路径
	 * 
	 * @return String 父路径
	 */
	public String getMediaFolderParentPath() {
		return mMediaFolderParentPath != null ? mMediaFolderParentPath : "";
	}

	/**
	 * 
	 * 设置文件夹父路径
	 * 
	 * @param mediaFolderParentPath
	 *            父路径
	 * @return void
	 */
	public void setMediaFolderParentPath(String mediaFolderParentPath) {

		mMediaFolderParentPath = mediaFolderParentPath;
	}

	/**
	 * 
	 * 获取文件夹路径
	 * 
	 * @return String 文件夹路径
	 */
	public String getMediaFolderPath() {
		return mMediaFolderPath != null ? mMediaFolderPath : "";
	}

	/**
	 * 
	 * 设置文件夹路径
	 * 
	 * @param mediaFolderPath
	 *            文件夹路径
	 * @return void
	 */
	public void setMediaFolderPath(String mediaFolderPath) {

		mMediaFolderPath = mediaFolderPath;
	}

	public MediaFolder() {

	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeString(mMediaFolderName);
		out.writeString(mMediaFolderPath);
		out.writeString(mMediaFolderParentPath);
		out.writeLong(mMediaFolderTotalSize);
		out.writeInt(mMediaFolderTotalNum);
		int mediaFileCount = 0;
		if (mMediaFileList != null && mMediaFileList.size() > 0) {
			mediaFileCount = mMediaFileList.size();
			out.writeInt(mediaFileCount);
			for (int i = 0; i < mediaFileCount; i++) {
				out.writeParcelable(mMediaFileList.get(i), flags);
			}
		} else {
			out.writeInt(mediaFileCount);
		}
	}

	public static final Parcelable.Creator<MediaFolder> CREATOR = new Parcelable.Creator<MediaFolder>() {
		public MediaFolder createFromParcel(Parcel in) {
			return new MediaFolder(in);
		}

		public MediaFolder[] newArray(int size) {
			return new MediaFolder[size];
		}
	};

	private MediaFolder(Parcel in) {
		mMediaFolderName = in.readString();
		mMediaFolderPath = in.readString();
		mMediaFolderParentPath = in.readString();
		mMediaFolderTotalSize = in.readLong();
		mMediaFolderTotalNum = in.readInt();
		int meidaFileCount = in.readInt();

		if (meidaFileCount > 0) {
			mMediaFileList = new ArrayList<MediaFile>();
			MediaFile mediaFile = null;
			for (int i = 0; i < meidaFileCount; i++) {
				mediaFile = in.readParcelable(MediaFile.class.getClassLoader());

				mMediaFileList.add(mediaFile);
			}
		} else {
			mMediaFileList = null;
		}

	}
}
